#
# PANEL lib Makefile
#
include ../../../../Makefile.param

PANEL_PATH := $(PANEL_ROOT)
EXT_PATH := $(PANEL_PATH)/ext_drv
LIB_PATH = $(PANEL_PATH)/lib
OBJ_PATH = ./obj

PANEL_INC := -I$(COMM_INC)\
			-I$(PANEL_PATH)/user/include\

LIB_A := $(LIB_PATH)/libpanel_eos_default.a
LIB_S := $(LIB_PATH)/libpanel_eos_default.so

ARFLAGS = rcv
CFLAGS += -Wall -fPIC

ifeq ($(EIGDB),EI_GDB)
CFLAGS += -g
endif

CFLAGS  += -O2
CFLAGS  += $(LIBS_CFLAGS)
DFLAGS  := -DEXT_REG
DFLAGS  += $(MDP_CFLAGS)

DEPEND_FILE := $(foreach file,$(subst -I, ,$(PANEL_INC)), $(wildcard $(file)/*.h))
SRCS = $(wildcard ./*.c)
OBJS = $(SRCS:%.c=%.o)
OBJS := $(OBJS:./%=obj/%)

COMPILE = $(CC) $(CFLAGS) $(DFLAGS) $(PANEL_INC) -lm

$(OBJ_PATH)/%.o: ./%.c $(DEPEND_FILE)
	@(echo "compiling $< ...")
	@[ -e $(LIB_PATH) ] || mkdir -p $(LIB_PATH)
	@[ -e $(OBJ_PATH) ] || mkdir -p $(OBJ_PATH)
	@($(COMPILE) -o $@ -c $<)

all:$(OBJS)
	@($(AR) $(ARFLAGS) $(LIB_A) $(OBJS))
	@($(CC) $(LIBS_LD_CFLAGS) -shared -fPIC -o $(LIB_S) $(OBJS))
	@mkdir -p $(INS_LIB)
	@cp $(LIB_S) $(INS_LIB)
	@cp $(LIB_A) $(INS_LIB)
clean:
	@$(RM) -rf $(LIB_A) $(LIB_S) $(OBJS)
	@$(RM) -rf $(LIB_PATH) $(OBJ_PATH)

